﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using System.Xml;
using System.IO;

namespace Hack_Dot_exe
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btnCreate_Click(object sender, EventArgs e)
        {
            if (txbPassword.Text == txbRePassword.Text) 
            {                
                string dir = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
                
                string file = dir + @"\User Saves\" + txbCreateUser.Text + ".sav";

                FileStream CU = new FileStream(file, FileMode.Create);

                XmlWriterSettings settings = new XmlWriterSettings();
                settings.Indent = true;
                settings.OmitXmlDeclaration = true;
                settings.NewLineOnAttributes = true;
                
                XmlWriter wr = XmlWriter.Create(CU, settings);

                wr.WriteStartDocument();

                wr.WriteStartElement("GameSave");
                wr.WriteStartElement("ComputerLogin");
                wr.WriteAttributeString("UserID", txbCreateUser.Text.ToString());
                wr.WriteAttributeString("UserPass", txbPassword.Text.ToString());
                wr.WriteEndElement();
                wr.WriteEndElement();
                wr.WriteEndDocument();
                wr.Flush();
                CU.Close();
            }
        }

        private void btnNUser_Click(object sender, EventArgs e)
        {
            pnlLogin.Visible = false;
            pnlNewUser.Visible = true;
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            pnlLogin.Visible = true;
            pnlNewUser.Visible = false;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string dir = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
            string sav = dir + @"\User Saves\";
            string[] gsave = Directory.GetFiles( sav,"*.sav");
            string save;
            foreach (string arrItem in gsave)
            {
                save = arrItem;
                save = save.Split('\\').Last();
                if (save.EndsWith(".sav"));
                    save = save.Remove(save.Length - 4);
                cbxUser.Items.Add(save);
            }
        }

        private void cbxUser_SelectedIndexChanged(object sender, EventArgs e)
        {
            string dir = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
            string sav = dir + @"\User Saves\";
            string[] passGet = new []{"UserPass"};
            XmlTextReader reader = new XmlTextReader(sav);
            if ( passGet
    }
}
